local gebo = fk.CreateSkill {
  name = "tyj_heg__gebo_manoeuvre",
}
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"
Fk:loadTranslationTable {
  ["tyj_heg__gebo_manoeuvre"] = "戈帛⇋",
  [":tyj_heg__gebo_manoeuvre"] = "出牌阶段限一次，你可以与一名角色拼点，赢的角色可以令一名拼点牌为【杀】的角色回复1点体力。",
}
gebo:addEffect("active", {
  anim_type = "support",
  card_num = 0,
  min_target_num = 1,
  max_target_num = 1,
  prompt = "戈帛：与一名角色拼点。",
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(gebo.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected < 1 and to_select ~= player and player:canPindian(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:sortByAction(effect.tos)
    local pd = U.jointPindian(player, effect.tos, gebo.name)
    if pd.winner and pd.winner:isAlive() then
      local recover = {}
      local cid = pd.fromCard:getEffectiveId()
      if cid and Fk:getCardById(cid).trueName == "slash" then
        table.insert(recover, pd.from.id)
      end
      for _, pid in ipairs(effect.tos) do
        if pd.results[pid] and pd.results[pid].toCard then
          if pd.results[pid].toCard and pd.results[pid].toCard.trueName == 'slash' then
            table.insert(recover, pid)
          end
        end
      end
      if table.contains(recover, pd.winner) then
        table.removeOne(recover, pd.winner)
      end
      if #recover > 0 then
        local to = room:askToChoosePlayers(pd.winner, {
        targets = recover,
        min_num = 1,
        max_num = 1,
        prompt = "戈帛：是否令一名拼点牌为【杀】的角色各回复1点体力？？",
        skill_name = gebo.name,
        cancelable = true,
      })
    if #to>0 then
      room:sortByAction(to)
      for _, p in ipairs(to) do
            if p:isAlive() then
              room:recover { num = 1, skillName = gebo.name, who = p, recoverBy = pd.winner }
            end
          end
    end
      end
    end
  end,
})

return gebo
